package com.ecnu.codelearn.controller;

import com.ecnu.codelearn.javabean.ParamDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @Author: 曹培胜
 * @Date: 2021/09/11/15:42
 * @Description:
 */
@RestController
@Slf4j
@Validated
public class ValidationController {
    @RequestMapping("/testDemo")
    public String demo01(@RequestBody @Valid ParamDto param, BindingResult bindingResult) {
        log.info("/demo...start..." + param.toString());
        if (bindingResult.hasErrors()) {
            return bindingResult.getFieldError().getDefaultMessage();
        }
        return "SUCCESS!" + param.toString();
    }
}
